#!/bin/bash
#使用说明，该文件放到项目根目录，即makeMtk(mk)同目录下，并根据项目赋值trunk,project,branch,然后使用如下命令：
#./m                            #拷贝目标文件到version_save目录(也可双击执行该文件)
#./m n                          #全编译new
#./m r                          #更新编译remake
#./m c                          #清除编译clean
#./m mm 模块名1 模块名2 ...       #单独编译多个模块mm



#主干名(在当前目录下查找：/mediatek/config/主干名/项目名/分支名)
trunk="joytech72_wet_jb3";
#项目名
project="";
#分支名
branch="";



###########无参数时拷贝bin文件到~/work/version_save/projname目录###########
if [[ ! -d "~/work/version_save" ]]; then  
    mkdir ~/work/version_save
fi  


if [ -z "$1" ] #无参数
then 

if [ -z "$project" ] #project空
then

#删除目录
rm -rf ~/work/version_save/${trunk}
mkdir  ~/work/version_save/${trunk}
#拷贝目录
chmod a+r out/target/product/${trunk}/*
cp -f out/target/product/${trunk}/*   ~/work/version_save/${trunk}
echo success!
exit;

else #else if project空

#删除目录
rm -rf ~/work/version_save/${trunk}-${project}[${branch}]
mkdir  ~/work/version_save/${trunk}-${project}[${branch}]
#拷贝目录
chmod a+r out/target/product/${trunk}/*
cp -f out/target/product/${trunk}/*   ~/work/version_save/${trunk}-${project}[${branch}]
echo success!
exit;

fi #end if project空

fi #end if 无参数


###########1个参数时,"n":new; "r":remake; "c":clean###########
if [ -z "$2" ] #只有1个参数
then


if [ -z "$project" ] #project空
then

case "$1" in 
"n") 
echo "./mk $trunk new"
./mk $trunk n
exit;
;;

"new") 
echo "./mk $trunk new"
./mk $trunk n
exit;
;;

"c") 
echo "./mk $trunk clean"
./mk $trunk c
exit;
;;

"clean") 
echo "./mk $trunk clean"
./mk $trunk c
exit;
;;

"r") 
echo "./mk $trunk remake"
./mk $trunk r
exit;
;;

"remake") 
echo "./mk $trunk remake"
./mk $trunk r
exit;
;;
esac #end case


else #else if project空


case "$1" in 
"n") 
echo "./mk $trunk $project[$branch] new"
./mk $trunk $project[$branch] n
exit;
;;

"new") 
echo "./mk $trunk $project[$branch] new"
./mk $trunk $project[$branch] n
exit;
;;

"c") 
echo "./mk $trunk $project[$branch] clean"
./mk $trunk $project[$branch] c
exit;
;;

"clean") 
echo "./mk $trunk $project[$branch] clean"
./mk $trunk $project[$branch] c
exit;
;;

"r") 
echo "./mk $trunk $project[$branch] remake"
./mk $trunk $project[$branch] r
exit;
;;

"remake") 
echo "./mk $trunk $project[$branch] remake"
./mk $trunk $project[$branch] r
exit;
;;
esac #end case

fi #end if project空

fi #end if 只有1个参数


###########mm编译模块时,有2～n个参数,模块名可以带单引号,"mm 模块全路径名1 模块全路径名2 ..."###########
if [ "$1" == "mm" ] #参数1为mm,参数2,参数3,参数4,...为模块名,中间空格隔开
then

if [ -n "$2" ] #参数2非空,模块全路径名1
then
echo "./mk mm $2"
./mk mm $2
fi #end if

if [ -n "$3" ] #参数3非空,模块全路径名2
then
echo "./mk mm $3"
./mk mm $3
fi #end if

if [ -n "$4" ] #参数4非空,模块全路径名3
then
echo "./mk mm $4"
./mk mm $4
fi #end if

if [ -n "$5" ] #参数5非空,模块全路径名4
then
echo "./mk mm $5"
./mk mm $5
fi #end if

if [ -n "$6" ] #参数6非空,模块全路径名5
then
echo "./mk mm $6"
./mk mm $6
fi #end if

if [ -n "$7" ] #参数7非空,模块全路径名6
then
echo "./mk mm $7"
./mk mm $7
fi #end if

if [ -n "$8" ] #参数8非空,模块全路径名7
then
echo "./mk mm $8"
./mk mm $8
fi #end if

if [ -n "$9" ] #参数9非空,模块全路径名8
then
echo "./mk mm $9"
./mk mm $9
fi #end if

fi #end if

